home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / comm / comm5 / nwsbrkr5.lha / Reader / NewsBreaker / src / NewsBreaker.c < prev    next >
C/C++ Source or Header  |  1996-12-16  |  8KB  |  305 lines

  1. /*
  2.  * Newsbreaker.c
  3.  *
  4.  * Hier das Hauptprogramm, incl. main().
  5.  *
  6.  */
  7.  
  8. #include <Includes.h>            /* System-/OS-Includes, -Protos */
  9. #include <Globals.h>        /* globale Variablen */
  10. #include <Protos.h>             /* Funktions-Prototypen */
  11. #include <Module.h>        /* Funktionen */
  12.  
  13.  
  14. /*
  15.  * Lieber Leser, liebe Leserin.
  16.  *
  17.  * Vielen Dank für Dein Interesse am NewsBreaker-Source.
  18.  *
  19.  * Dieser Code ist das Ergebnis von zwei Jahren UMS-
  20.  * und C- "Learning by doing".
  21.  *
  22.  * ACHTUNG
  23.  * die längeren Kommentare, Texte zu Systemroutinen usw. habe
  24.  * ich in erster Line für mich geschrieben. Mein Ziel
  25.  * war, die Funktionen besser zu verstehen.
  26.  *
  27.  * Also: bitte
  28.  * meine Texte nicht zu wörtlich nehmen. Sie sind
  29.  * kein Ersatz für den Blick in die "richtige"
  30.  * Dokumentation oder Original-Autodocs.
  31.  *
  32.  * Außerdem benutze ich (als Hobbyprogrammierer) mal den einen
  33.  * oder anderen Fachbegriff auf meine eigene Art.
  34.  *
  35.  * Ich denke, die Texte sind eine gute Zusammenfassung:
  36.  * deshalb ideal für den ersten Überblick und
  37.  * schnellen Einstieg.
  38.  *
  39.  *
  40.  * Wer Fehler findet, Vorschläge bringt:
  41.  * über jede Korrektur, jeden Tip
  42.  * freue ich. Idealerweise als E-Mail.
  43.  * Bitte Originaltext kurz zitieren.
  44.  *
  45.  * An:  <sm@mk2.maus.sauerland.de>.
  46.  * Thanks in advance!
  47.  */
  48.  
  49.  
  50.  
  51. #define MINLIB 39        /* Mindestversion für AmigaOS-Libraries*/
  52.  
  53. int
  54. main (int argc, char *argv[])
  55. {
  56.   BOOL okay = FALSE;
  57.   ULONG exitvalue = NULL;
  58.   TextFieldBase = NULL;
  59.  
  60.   printf ("\n\n\n--------- Programm Start " NB_VERSION " ---\n\n");
  61.  
  62. /* Öffne benötigte Libraries. Exec und Dos sind schon offen */
  63.  
  64.   if (IntuitionBase = OpenLib ("intuition.library", MINLIB))
  65.     if (GfxBase = OpenLib ("graphics.library", MINLIB))
  66.       if (IFFParseBase = OpenLib ("iffparse.library", MINLIB))
  67.     if (GadToolsBase = OpenLib ("gadtools.library", MINLIB))
  68.       if (UtilityBase = OpenLib ("utility.library", MINLIB))
  69.         if (DataTypesBase = OpenLib ("datatypes.library", MINLIB))
  70.           if (DiskFontBase = OpenLib ("diskfont.library", MINLIB))
  71.         if (UMSBase = OpenLib ("ums.library", 11L))
  72.           if (UMSSupportBase = OpenLib ("umssupport.library", 0L))
  73.             if (TextFieldBase = OpenLib ("gadgets/textfield.gadget", 0))
  74.               if (gLib = OpenLib ("gadgets/button.gadget", 37))
  75.             if (TextLabelBase = OpenLibrary ("textitem.class", 0))
  76.               if (ItemListBase = OpenLibrary ("itemlist.class", 0))
  77.                 if (CompListViewBase = OpenLibrary ("complistview.class", 0))
  78.                   {
  79.                 okay = TRUE;    /* alles ist da */
  80.                   }
  81.                 else
  82.                   {
  83.                 if (IntuitionBase)    /*  (ShowError() öffnet Intuition/EasyRequest) */
  84.                   ShowError ("Nicht alle Libraries wurden erfolgreich geöffnet.\nAbbruch!");
  85.                   }
  86.  
  87. /*
  88.    todo: UMS Standard für Login implementieren.
  89.  
  90.    Prob: wie wird WBench-Message korrekt ausgewertet? Außerdem
  91.    muß ein GUI dafür gebaut werden, drei string.gadgets usw. ala
  92.    IntuiNews.
  93.  */
  94.  
  95.   if (okay)
  96.     {
  97.       okay = Login ();        /* beschaffe diese Strings */
  98.     }
  99.  
  100.   if (okay)
  101.     {
  102.       account = UMSRLogin (server, user, passwd);
  103.       if (!account)
  104.     {
  105.       ShowError ("Login fehlgeschlagen.\nAbbruch!");
  106.     }
  107.     }
  108.  
  109.   if (account)
  110.     {
  111.       ReadConfig ();
  112.     }
  113.  
  114. /*
  115.    Fenster öffnen.
  116.    Die zahlreichen Parameter in OpenWindowTags() bestimmen Aussehen und
  117.    Eigenschaften des NewsBreaker-Fensters: 
  118.    - Wie groß?
  119.    - Welche System-Gadgets?
  120.  
  121.    Parameter:
  122.    Kann das Fenster verschoben werden, kann es auf einem anderen Screen
  123.    auftauchen, eventuell als 'Backdrop' komplett ausfüllen? (n/a)
  124.  
  125.    Taglisten:
  126.    Es könnte eine Prefs-Tagliste geben, die ti-Data Werte in die hardcoded
  127.    Tagliste werden gemischt.
  128.  */
  129.  
  130.   if (account)
  131.     {
  132.       TextFieldClass = TEXTFIELD_GetClass ();
  133.  
  134.       /* Hauptfenster öffnen */
  135.       Mywindow = OpenWindowTags (NULL,
  136.                  WA_Flags, WFLG_DEPTHGADGET |
  137.                  WFLG_DRAGBAR |
  138.                  WFLG_CLOSEGADGET |
  139.                  WFLG_SIZEGADGET |
  140.                  WFLG_SIZEBBOTTOM |
  141.                  WFLG_SIZEBRIGHT,
  142.                  WA_Activate, TRUE,
  143.                  WA_IDCMP, IDCMP_CLOSEWINDOW |
  144.                  IDCMP_REFRESHWINDOW |
  145.                  IDCMP_VANILLAKEY |
  146.                  IDCMP_RAWKEY |
  147.                  IDCMP_GADGETUP |
  148.                  IDCMP_IDCMPUPDATE |
  149.                  IDCMP_MENUPICK,
  150.                  WA_Top, 5,
  151.                  WA_Left, 10,
  152.                  WA_NewLookMenus, TRUE,
  153.                  WA_ScreenTitle, NB_VERSION,
  154.                  WA_Title, NB_NAME,    /* Title "NewsBreaker" */
  155.                        //WA_Width, 0,
  156.                        //WA_Height, 0,
  157.                  TAG_DONE);
  158.     }
  159.  
  160. /*
  161.    1. Signale.
  162.    -----------
  163.    Unter Amiga OS warten Tasks und Prozesse auf bestimmte
  164.    Signale. Der Wert im mp_SigBit-Feld vom Window-Userport
  165.    ist die Nummer eines bestimmten Signals. Auf dieses
  166.    Signal wartet NewsBreaker.
  167.  
  168.    Ereignisse, die bei Fenstern auftreten, erzeugen ein Signal für den
  169.    NewsBreaker-Prozeß. Beispiele: Menupunkt ausgewählt, Gadget angeklickt,
  170.    Taste gedrückt.
  171.  
  172.    Das Signal erreicht den wartenden Prozeß. NewsBreaker wacht auf
  173.    und verarbeitet die dann eventuell eingetroffenen Messages. Zu
  174.    den Messages mehr in <MainLoop.c>.
  175.  
  176.    2. DrawInfo.
  177.    ------------
  178.    DrawInfo wurde in OS 2.0 eingeführt, um das allgemeine
  179.    Aussehen von Amiga-GUIs zu verbessern. DrawInfo enthält
  180.    u.a. Farbnummern (pens) für zahlreiche Grafikelemente.
  181.    NewsBreaker richtet sich nach diesen (User-)Vorgaben. Grafiken
  182.    und Schriften werden passend zur restlichen, nicht-
  183.    NewsBreaker-Oberfläche eingefärbt. Das ergibt ein einheitliches
  184.    Erscheinungsbild.
  185.  
  186.    GetScreenDrawInfo() holt die DrawInfo-Struktur systemkonform aus der
  187.    Screen-Struktur, beachtet Zugriffsrechte auf die Screen-Struktur.
  188.  */
  189.  
  190.   if (Mywindow)
  191.     {
  192.       window_sig = 1L << Mywindow->UserPort->mp_SigBit;        /* Signal für IDCMP */
  193.       sigs = window_sig;
  194.       dri = GetScreenDrawInfo (Mywindow->WScreen);    /* DrawInfo */
  195.     }
  196.  
  197.   if (dri)
  198.     {
  199.       pens = dri->dri_Pens;
  200.  
  201.       /* Abstände Gadgets zu Rahmen festlegen todo */
  202.  
  203. /* dies wird eine IBox: A data structure common in V36 Intuition
  204.    processing: struct IBox { WORD Left; WORD Top; WORD Width; WORD Height;}; */
  205.  
  206.       /*IBox gap */
  207.       gap_w = Mywindow->RPort->TxWidth;
  208.       gap_h = Mywindow->RPort->TxHeight;
  209.  
  210.       /* setze Rahmen Informationsfeldes infobar todo */
  211.       /* das wird eine IBox infobar */
  212.       infobar_h = (Mywindow->RPort->TxHeight * 3) / 2;
  213.  
  214.       /* Ändere die Fensterausdehnung */
  215.       WindowLimits (Mywindow, 160, Mywindow->BorderTop + Mywindow->BorderBottom + Mywindow->WScreen->RastPort.TxHeight + 46, -1, -1);
  216.       creategads (Mywindow);    /* BOOPSI Gadgets */
  217.  
  218.       okay = CreateMyMenus ();    /* Intuition Menus erzeugen */
  219.  
  220.     }
  221.   else
  222.     {
  223.       okay = FALSE;
  224.     }
  225.  
  226.   if (okay)
  227.     {
  228.       /* Displayfeld löschen -- todo */
  229.       InfoBarClear (Mywindow, infobar_h);    /* todo */
  230.  
  231.       MainLoop ();        /* Einsprung in Hauptschleife */
  232.     }
  233.   else
  234.     {
  235.       ShowError ("SCHWERER FEHLER!\nKonnte MainLoop nicht starten\n");
  236.     }
  237.  
  238. /*----------------- Aufräumen -------------------- */
  239.  
  240.  
  241.   if (Mywindow)
  242.     {
  243.       RemoveMyMenus ();        /* Intuition Menus entfernen */
  244.  
  245.       if (gLib)
  246.     {
  247.       deletegads (Mywindow);
  248.       CloseLibrary ((struct Library *) gLib);
  249.     }
  250.       CloseWindow (Mywindow);
  251.     }
  252.  
  253.   if (account)
  254.     {
  255.       UMSLogout (account);
  256.     }
  257.  
  258.  
  259. /* globale Listen */
  260.  
  261.   if (GlobGroupList)
  262.     {
  263.       FreeMyList (GlobGroupList); /* interne Liste löschen */
  264.       GlobGroupList = NULL;
  265.     }
  266.  
  267.   if (GlobMsgList)
  268.     {
  269.       SetGlobMsgList (NULL);    /* Globale korrigieren */
  270.       SetGlobMsgGroup (NULL);    /* String löschen */
  271.     }
  272.  
  273.   if (AktMsgGroup)
  274.     {
  275.       printf ("free(AktMsgGroup) String %s\n", AktMsgGroup);
  276.       free (AktMsgGroup);
  277.       AktMsgGroup = NULL;
  278.     }
  279.  
  280.   CloseLibrary (IntuitionBase);
  281.   CloseLibrary (GfxBase);
  282.   CloseLibrary (IFFParseBase);
  283.   CloseLibrary (GadToolsBase);
  284.   CloseLibrary (UtilityBase);
  285.   CloseLibrary (DataTypesBase);
  286.   CloseLibrary (DiskFontBase);
  287.   CloseLibrary (UMSBase);
  288.   CloseLibrary (UMSSupportBase);
  289.   CloseLibrary (ItemListBase);
  290.   CloseLibrary (TextLabelBase);
  291.   CloseLibrary (CompListViewBase);
  292.  
  293.   TextFieldClass = NULL;
  294.   CloseLibrary (TextFieldBase);
  295.  
  296.  
  297.   printf ("--------- Programm Ende " NB_VERSION " ---\n");
  298.  
  299.   exit (exitvalue);
  300.  
  301. /* todo: check ob alle Ressourcen geschlossen werden. */
  302. /* todo: 17K wurden/werden nicht freigegeben !!! */
  303.  
  304. }                /* END MAIN */
  305.